package com.yl.rabbitmq.day08;

import com.rabbitmq.client.Channel;
import com.yl.rabbitmq.utils.RabbitMQUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * @author yangl
 */
public class TopicLogs {

    private final static String EXCHANGE_NAME = "topic_logs";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMQUtil.getChannel();

        Map<String, String> bindingMap = new HashMap<>();
        bindingMap.put("quick.orange.rabbit","被队列Q1Q2接收到");
        bindingMap.put("lazy.orange.elephant","被队列Q1Q2接收");
        bindingMap.put("quick.orange.fox","被队列Q1接收到");
        bindingMap.put("quick.brown.fox","被队列Q2接收到");
        bindingMap.put("lazy.pink.rabbit","虽然满足两个绑定但是只被Q2接收一次");
        bindingMap.put("quick.brown.fox","不匹配任何绑定不会被任何队列接收到时候会被丢弃");
        bindingMap.put("quick.orange.male.rabbit","是四个单词不匹配任何绑定会被丢弃");
        bindingMap.put("lazy.orange.male.rabbit","是四个单词但匹配Q2");
        for (Map.Entry<String, String> stringStringEntry : bindingMap.entrySet()) {
            String routingKey = stringStringEntry.getKey();
            String message = stringStringEntry.getValue();
            channel.basicPublish(EXCHANGE_NAME, routingKey, null, message.getBytes("UTF-8"));
            System.out.println("生产者发送的消息：" + message);
        }

    }
}
